package com.MedDroid.task;

import android.os.AsyncTask;
import com.MedDroid.activity.AddNewUserActivity;
import com.MedDroid.activity.EditProfileActivity;
import com.MedDroid.control.DatabaseControl;
import com.MedDroid.entities.User;

import java.lang.ref.WeakReference;

/**
 * Created with IntelliJ IDEA.
 * User: Romen
 * Date: 02/12/13
 * Time: 6:52 PM
 * Description:
 */
public class SubmitUserChangesTask extends AsyncTask<Integer, Void, Void>
{
	DatabaseControl DatabaseC;
	WeakReference<EditProfileActivity> UserPage;

	public SubmitUserChangesTask(DatabaseControl Data, EditProfileActivity activity)
	{
		DatabaseC = Data;
		UserPage = new WeakReference<EditProfileActivity>(activity);
	}

	@Override
	protected Void doInBackground(Integer... UserID)
	{
		EditProfileActivity Page = UserPage.get();
		User UpdatedUser = DatabaseC.getUser(UserID[0]);
		UpdatedUser.setValues(
			Page.EditFirstName.getText().toString(),
			Page.EditMiddleName.getText().toString(),
			Page.EditLastName.getText().toString(),
			Page.EditPhoneNumber.getText().toString(),
			Page.EditAddressLine.getText().toString(),
			Page.EditCity.getText().toString(),
			Page.EditProvince.getText().toString(),
			Page.EditCountry.getText().toString(),
			Page.EditPostalCode.getText().toString(),
			Page.EditEmergencyFullName.getText().toString(),
			Page.EditEmergencyPhoneNumber.getText().toString()
		);
		DatabaseC.updateUser(UserID[0],UpdatedUser);
		return null;
	}

	@Override
	protected void onPostExecute(Void V)
	{

	}
}
